<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
  <!-- v-on 监听子事件 -->
  <cpn v-on:itemclick="cpnClick"></cpn>
</div>
</body>
<template id="cpn">
  <div>
    <button v-for="item in catagories" @click="butClick(item)">{{item.name}}</button>
  </div>
</template>
<script src="../js/vue.js"></script>
<script>
  // 子传父
  const cpn = {
    template: "#cpn",
    // props: ["cmovies", "cmessage"], // 变量
    props: {},
    data() {
      return {
        catagories: [
          {id: "aaa", name: "热门推荐"},
          {id: "bbb", name: "手机数码"},
          {id: "ccc", name: "家用电器"},
          {id: "ddd", name: "电脑办公"},
        ],
      };
    },
    methods: {
      butClick(item) {
        // console.log(item);
        // $emit 发射事件:自定义事件
        this.$emit("itemclick", item);
      }
    },
  }

  let app = new Vue({
    el: "#app",
    data: {
      message: "aaa",
      movies: ["英雄", "无极", "赤壁", "影"],
    },
    components: {
      cpn
    },
    methods: {
      cpnClick(item) {
        console.log("cpnClick", item);
      }
    },
  });
</script>
</html>